/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.gr.jcash.dmp;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author gelson
 */
@Entity
@Table(name = "movimento", catalog = "jcash", schema = "public")
@NamedQueries({
    @NamedQuery(name = "Movimento.buscarTodos", query = "SELECT m FROM Movimento m  WHERE m.usuario = :p0 ORDER BY m.mvtData DESC"),
    @NamedQuery(name = "Movimento.buscarPorId", query = "SELECT m FROM Movimento m WHERE m.idMvt = :p0"),
    @NamedQuery(name = "Movimento.buscarPorData", query = "SELECT m FROM Movimento m WHERE m.mvtData = :p0 AND m.usuario = :p1"),
    @NamedQuery(name = "Movimento.buscarPorValor", query = "SELECT m FROM Movimento m WHERE m.mvtValor = :p0 AND m.usuario = :p1"),
    @NamedQuery(name = "Movimento.buscarPorDocumento", query = "SELECT m FROM Movimento m WHERE m.mvtDocumento = :p0 AND m.usuario = :p1"),
    @NamedQuery(name = "Movimento.buscarPorHistorico", query = "SELECT m FROM Movimento m WHERE m.mvtHistorico = :p0 AND m.usuario = :p1"),
    @NamedQuery(name = "Movimento.buscarPorObservacao", query = "SELECT m FROM Movimento m WHERE m.mvtObservacao = :p0 AND m.usuario = :p1"),
    @NamedQuery(name = "Movimento.buscarPorBaixado", query = "SELECT m FROM Movimento m WHERE m.mvtBaixado = :p0 AND m.usuario = :p1"),
    @NamedQuery(name = "Movimento.buscarPorTransferencia", query = "SELECT m FROM Movimento m WHERE m.mvtTransferencia = :p0 AND m.usuario = :p1"),
    @NamedQuery(name = "Movimento.count", query = "SELECT COUNT(m.idMvt) FROM Movimento m WHERE m.usuario = :p0"),
    @NamedQuery(name = "Movimento.countPorConta", query = "SELECT COUNT(m.idMvt) FROM Movimento m WHERE m.usuario = :p0 AND (m.ctaDestino = :p1 OR m.ctaOrigem = :p2)"),
    @NamedQuery(name = "Movimento.somaSaidasEntreDataPorConta", query = "select sum(m.mvtValor) from Movimento m where m.usuario = :p0 and m.ctaOrigem =:p1 and m.mvtData >= :p2 and m.mvtData < :p3 "),
    @NamedQuery(name = "Movimento.somaEntradasEntreDataPorConta", query = "select sum(m.mvtValor) from Movimento m where m.usuario = :p0 and m.ctaDestino =:p1 and m.mvtData >= :p2 and m.mvtData < :p3 "),
    @NamedQuery(name = "Movimento.porContaEntreDatas", query = "select m from Movimento m where m.usuario =:p0 and (m.ctaDestino =:p1 or m.ctaOrigem = :p2) and m.mvtData between :p3 and :p4 order by m.mvtData, m.idMvt")
})
public class Movimento extends EntidadeBase implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_mvt", nullable = false)
    private Long idMvt;
    @Basic(optional = false)
    @NotNull
    @Column(name = "mvt_data", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date mvtData;
    @Basic(optional = false)
    @NotNull
    @Column(name = "mvt_valor", nullable = false, precision = 2)
    private BigDecimal mvtValor;
    @Size(max = 20)
    @Column(name = "mvt_documento", length = 20)
    private String mvtDocumento;
    @Size(max = 100)
    @Column(name = "mvt_historico", length = 100)
    private String mvtHistorico;
    @Size(max = 100)
    @Column(name = "mvt_observacao", length = 100)
    private String mvtObservacao;
    @Basic(optional = false)
    @NotNull
    @Column(name = "mvt_baixado", nullable = false)
    private boolean mvtBaixado;
    @Basic(optional = false)
    @NotNull
    @Column(name = "mvt_transferencia", nullable = false)
    private boolean mvtTransferencia;
    @JoinColumn(name = "id_usu", referencedColumnName = "id_usu", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Usuario usuario;
    @JoinColumn(name = "cta_destino", referencedColumnName = "id_cta", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Conta ctaDestino;
    @JoinColumn(name = "cta_origem", referencedColumnName = "id_cta", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Conta ctaOrigem;

    public Movimento() {
    }

    public Long getIdMvt() {
        return idMvt;
    }

    public void setIdMvt(Long idMvt) {
        this.idMvt = idMvt;
    }

    public Date getMvtData() {
        return mvtData;
    }

    public void setMvtData(Date mvtData) {
        this.mvtData = mvtData;
    }

    public BigDecimal getMvtValor() {
        return mvtValor;
    }

    public void setMvtValor(BigDecimal mvtValor) {
        this.mvtValor = mvtValor;
    }

    public String getMvtDocumento() {
        return mvtDocumento;
    }

    public void setMvtDocumento(String mvtDocumento) {
        this.mvtDocumento = mvtDocumento;
    }

    public String getMvtHistorico() {
        return mvtHistorico;
    }

    public void setMvtHistorico(String mvtHistorico) {
        this.mvtHistorico = mvtHistorico;
    }

    public String getMvtObservacao() {
        return mvtObservacao;
    }

    public void setMvtObservacao(String mvtObservacao) {
        this.mvtObservacao = mvtObservacao;
    }

    public boolean getMvtBaixado() {
        return mvtBaixado;
    }

    public void setMvtBaixado(boolean mvtBaixado) {
        this.mvtBaixado = mvtBaixado;
    }

    public boolean getMvtTransferencia() {
        return mvtTransferencia;
    }

    public void setMvtTransferencia(boolean mvtTransferencia) {
        this.mvtTransferencia = mvtTransferencia;
    }

    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    public Conta getCtaDestino() {
        return ctaDestino;
    }

    public void setCtaDestino(Conta ctaDestino) {
        this.ctaDestino = ctaDestino;
    }

    public Conta getCtaOrigem() {
        return ctaOrigem;
    }

    public void setCtaOrigem(Conta ctaOrigem) {
        this.ctaOrigem = ctaOrigem;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idMvt != null ? idMvt.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Movimento)) {
            return false;
        }
        Movimento other = (Movimento) object;
        if ((this.idMvt == null && other.idMvt != null) || (this.idMvt != null && !this.idMvt.equals(other.idMvt))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.gr.jcash.dmp.Movimento[ idMvt=" + idMvt + " ]";
    }

    @Override
    public void setId(Long id) {
        this.idMvt = id;
    }

    @Override
    public Long getId() {
        return idMvt;
    }
}
